package main

import (
	"fmt"
	"sort"
)

func solution(n int, array []int) int {
	// Edit your code here
	var res []int
	for i := 0; i < n; i++ {
		for j := i + 1; j < len(array)+1; j++ {
			arr := array[i:j]
			sort.Ints(arr)
			if len(arr) != 0 {
				res = append(res, arr[0]*len(arr))
			} else {
				res = append(res, 0)
			}

		}
	}

	maxVal := 0
	for _, v := range res {
		if v > maxVal {
			maxVal = v
		}
	}

	return maxVal
}

func main() {
	// Add your test cases here

	fmt.Println(solution(5, []int{1, 2, 3, 4, 5}) == 9)
}
